package com.springboot.cloud.demos.feign.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author qjmove
 */
@Configuration
@Slf4j
public class BusConfig {

    //OSS 鉴黄
    public static final String QUEUE_NAME_OSS_SCAN = "JPUSH-MESSAGE_OSS_SCAN_QUEUE";


    public static final String QUEUE_NAME_FOLLOW = "JPUSH-MESSAGE_FOLLOW_QUEUE";
    public static final String QUEUE_NAME_SUPPORT = "JPUSH-MESSAGE_SUPPORT_QUEUE";
    public static final String QUEUE_NAME_COMMENT = "JPUSH-MESSAGE_COMMENT_QUEUE";
    public static final String QUEUE_NAME_SIGNUP = "JPUSH-MESSAGE_SIGNUP_QUENUE";
    public static final String QUEUE_NAME_SYSTEM = "JPUSH-MESSAGE_SYSTEM_QUENUE";
    //发布动态后，推送到关注我的好友
    public static final String QUEUE_NAME_PUSH = "JPUSH-MESSAGE_PUSH_QUEUE";

    public static final String EXCHANGE_NAME = "JPUSH-MESSAGE_EXCHANGE";


    /***声明交换机
     *
     * @return
     */
    @Bean("topicExchange")
    public Exchange topicExchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    /**
     * 声明队列
     */
    @Bean("followQueue")
    public Queue followQueue() {
        return QueueBuilder.durable(QUEUE_NAME_FOLLOW).build();
    }

    /**
     * 声明队列
     */
    @Bean("supportQueue")
    public Queue supportQueue() {
        return QueueBuilder.durable(QUEUE_NAME_SUPPORT).build();
    }

    /**
     * 声明队列
     */
    @Bean("commentQueue")
    public Queue commentQueue() {
        return QueueBuilder.durable(QUEUE_NAME_COMMENT).build();
    }

    /**
     * 声明报名队列
     */
    @Bean("signUpQueue")
    public Queue signUpQueue() {
        return QueueBuilder.durable(QUEUE_NAME_SIGNUP).build();
    }

    /**
     * 声明队列
     */
    @Bean("systemQueue")
    public Queue systemQueue() {
        return QueueBuilder.durable(QUEUE_NAME_SYSTEM).build();
    }

    /**
     * 声明队列
     */
    @Bean("pushQueue")
    public Queue pushQueue() {
        return QueueBuilder.durable(QUEUE_NAME_PUSH).build();
    }

    /**
     * 声明鉴黄队列
     */
    @Bean("ossScanQueue")
    public Queue ossScanQueue() {
        return QueueBuilder.durable(QUEUE_NAME_OSS_SCAN).build();
    }

    /***绑定队列和交换机
     *
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding itemQueueExchange(@Qualifier("followQueue") Queue queue,
                                     @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("follow.#").noargs();
    }

    /***
     * 绑定队列和交换机
     *
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding supportQueueExchange(@Qualifier("supportQueue") Queue queue,
                                        @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("support.#").noargs();
    }

    @Bean
    public Binding commentQueueExchange(@Qualifier("commentQueue") Queue queue,
                                        @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("comment.#").noargs();
    }

    @Bean
    public Binding systemQueueExchange(@Qualifier("systemQueue") Queue queue,
                                       @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("system.#").noargs();
    }

    @Bean
    public Binding signUpQueueExchange(@Qualifier("signUpQueue") Queue queue,
                                       @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("signUp.#").noargs();
    }

    @Bean
    public Binding pushQueueExchange(@Qualifier("pushQueue") Queue queue,
                                     @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("push.#").noargs();
    }

    @Bean
    public Binding ossScanQueueExchange(@Qualifier("ossScanQueue") Queue queue,
                                     @Qualifier("topicExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("oss.#").noargs();
    }
}
